package org.mspring.mlog.event;

import com.google.common.eventbus.EventBus;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;

/**
 * @author Gao Youbo
 * @since 2015-11-07 14:49
 */
public class EventSender {
    private static final Logger LOG = LoggerFactory.getLogger(EventSender.class);

    private EventBus eventBus = new EventBus();

    public void send(BaseEvent event) {
        LOG.info("事件分发:{}", event.getClass().getName());
        eventBus.post(event);
    }

    public void setEventHandlers(List<BaseEventHandler> handlerList) {
        for (BaseEventHandler handler : handlerList) {
            LOG.info("注册事件处理器:{}", handler.getClass().getName());
            eventBus.register(handler);
        }
    }
}
